package com.tlsy.commerce.utils;

import com.google.common.collect.Maps;
import org.apache.commons.lang3.StringUtils;

import java.util.Map;

/**
 * 设置全局变量值
 * @author Tlsy
 * @version commerce 0.0.1
 * @date 2017/4/19  14:51
 */
public class AppConfig {


    /**
     * 用户登录后将基本信息放入session中
     */
    public static String USER_SESSION = "user";
    /**
     * 密码加密配置
     */
    public static final int SALT_SIZE=8;

    public static final int HASH_INTERATIONS=1024;

    public static final String HASH_ALGORITHM="SHA-1";

    /**
     * 保存全局属性值
     */
    private static Map<String, String> map = Maps.newHashMap();
    /**
     * 缓存配置
     */
    public static final String USER_CACHE="userCache";

    public static final String USER_CACHE_ID_="user_cache_id_";

    public static final String USER_CACHE_PHONE_="user_cache_phone_";

    public static final String USER_CACHE_NAME_="user_cache_name_";

    public static final String AUTH_TOKEN_CACHE="authTokenCache";

    public static final String SYS_CACHE="sysCache";

    public static final String PRODUCT_CACHE="productCache";

    public static final String PASSWORD_RETRY_CACHE="passwordRetryCache";

    /**
     * 属性文件加载对象
     */
    private static PropertyLoader loader = new PropertyLoader("base.properties");

    /**
     * 获取配置
     */
    public static String getConfig(String key) {
        String value = map.get(key);
        if (value == null){
            value = loader.getProperty(key);
            map.put(key, value != null ? value : StringUtils.EMPTY);
        }
        return value;
    }
}
